package com.topwalk.step01;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * 学习Atomic
 * 
 * @author tangfl
 * @since 2024/3/6
 */
@Slf4j
public class Demo10_1Atomic {
    
    public static void main(String[] args) {
        AtomicInteger count = new AtomicInteger();
        new Thread(() -> {
            for (int i = 0; i < 1000; i++) {
                int andAdd = count.getAndAdd(1);
                log.info("{}", andAdd);
            }
        }, "ThreadA").start();
        
        new Thread(() -> {
            for (int i = 0; i < 1000; i++) {
                int andAdd = count.getAndAdd(1);
                log.info("{}", andAdd);
            }
        }, "ThreadB").start();
    }
    
}
